import logging
import os

class Logger():

    def __init__(self, projectName):
        self.logger = logging.getLogger(projectName)
        self.logger.setLevel(logging.DEBUG)
        logDirPath = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__),
                'log'
            )
        )
        not os.path.exists(logDirPath) and os.mkdir(logDirPath)

        sh = logging.StreamHandler()
        fh = logging.FileHandler(
            filename=f"{logDirPath}/{projectName}.log",
            encoding='utf-8'
        )

        formatter = logging.Formatter(
            "%(asctime)s - %(levelname)s - %(filename)s - %(lineno)s - %(message)s"
        )

        sh.setFormatter(formatter)
        fh.setFormatter(formatter)

        self.logger.addHandler(sh)
        self.logger.addHandler(fh)

    def getLogger(self):
        return self.logger